package utils

import (
	"fmt"
	"ginblog/config"
	errMsg "ginblog/model/err"
	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

var Oss *oss.Client

func NewOssClient() error {
	var err error
	Oss, err = oss.New(config.EndPort, config.AccessKeyID, config.Secret, oss.Timeout(10, 120))
	if err != nil {
		errMsg.ErrorLog(err)
		return err
	}

	bucket, err := Oss.ListBuckets()
	if err != nil {
		errMsg.ErrorLog(err)
		return err
	}
	for _, item := range bucket.Buckets {
		fmt.Println(item.Name)
	}
	//location, err := Oss.GetBucketLocation("multi-media-xiao")
	errMsg.HandleError(err)
	//err = bucket.GetObjectToFile("my-object", "LocalFile")
	//if err != nil {
	//    HandleError(err)
	//}
	return err
}
